﻿import os
import numpy as np

'''Creates a dictionary with temperatures as keys and datasets as values

Input: Name of file extension and place of temperature values in index
Extension is a string, index is an integer
For the .chi and .gr files given, the default index value should be 12.
Test files should be taken out.
Output: Dictionary
Integers are keys
Arrays are values

Run in the directory where your files are stored.
'''

def getDataSets(ext, index):
    a = os.listdir(os.getcwd())
    b = []
    c = []
    d = {}
    #Creates a list of .chi files
    for x in a:
        if x[-1] is ext[-1] and x[-2] is ext[2]:
            b.append(x)
            
    #Creates a list of temperatures
    for x in b:
        c.append(int(x[index] + x[index + 1] + x[index + 2]))
        
        
    #Creates a dictionary with temperatures as keys to the name of datafiles
    for x in range(len(b)):
        d[c[x]] = b[x]
    
    #Replaces those names with the actual data
    if ext is "chi":
        e = d.keys()
        e.sort()
        for x in range(len(d)):
            d[e[x]] = np.loadtxt(os.getcwd() + d[e[x]], skiprows = 4)
            
        
    return d
